package cn.lystudio.rohmtimeopwide_background_v11.controller.appApi;

import cn.dev33.satoken.annotation.SaIgnore;
import cn.dev33.satoken.util.SaResult;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.lystudio.rohmtimeopwide_background_v11.entity.dto.AbnormalItemDTO;
import cn.lystudio.rohmtimeopwide_background_v11.service.AbnormalItemService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/app-api/abnormal")
@CrossOrigin
@SaIgnore
@Slf4j
public class AppAbnormalItemController {
    private AbnormalItemService abnormalItemService;

    @Autowired
    @Lazy
    public void setAbnormalItemService(AbnormalItemService abnormalItemService) {
        this.abnormalItemService = abnormalItemService;
    }
    @GetMapping("/getAbnormalItemListByMachineNo")
    public SaResult getAbnormalItemListByMachineNo(@Param("machineNo")String machineNo){
        List<AbnormalItemDTO> abnormalItemList = abnormalItemService.getAbnormalItemListByMachineNo(machineNo);
        if(CollUtil.isEmpty(abnormalItemList)) return SaResult.error("该机台下没有操作项");
        return SaResult.data(abnormalItemList);
    }

    @GetMapping("/getAbnormalItemByOpItemNameAndMachineNo")
    public SaResult getAbnormalItemByOpItemNameAndMachineNo(String opItemName,String machineNo){
        AbnormalItemDTO abnormalItem = abnormalItemService.getAbnormalItemByOpItemNameAndMachineNo(opItemName, machineNo);
        if(ObjectUtil.isEmpty(abnormalItem)) return SaResult.error("设置值已变更,无法修改数据");
        return SaResult.data(abnormalItem);
    }



}
